﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;

namespace BLL
{
    public class GiaoVienBLL
    {
        QuanLyDiemDataContext DB = new QuanLyDiemDataContext();
        public bool Insert(GiaoVienDTO giaovien)
        {
            try
            {
                GiaoVien gv = new GiaoVien();
                gv.MaCanBo = giaovien.MaCanBo;
                gv.MaTo = giaovien.MaTo;
                DB.GiaoViens.InsertOnSubmit(gv);
                DB.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool Update(GiaoVienDTO giaovien)
        {
            try
            {
                GiaoVien gv = DB.GiaoViens.Where(s => s.MaCanBo == giaovien.MaCanBo).FirstOrDefault();
                gv.MaTo = giaovien.MaTo;
                DB.GiaoViens.InsertOnSubmit(gv);
                DB.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool Delete(string macanbo)
        {
            try
            {
                GiaoVien gv = DB.GiaoViens.Where(s => s.MaCanBo == macanbo).FirstOrDefault();
                DB.GiaoViens.DeleteOnSubmit(gv);
                DB.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        
    }
}
